﻿using System;
using System.Collections.Generic;
using System.Web;

namespace Triad.Common
{
/// <summary>
    /// Partial store class for session variables pertaining to User information.
/// </summary>
    public partial class store
    {
        /// <summary>
        /// Session Variable properties for Defects
        /// </summary>
        public class User
        {
            /// <summary>
            /// Clear a single session variable from the IIS Server's memory
            /// </summary>
            /// <param name="strName"></param>
            public static void Clear(string strName)
            {
                if (HttpContext.Current.Session[strName] != null)
                    HttpContext.Current.Session.Remove(strName);
            }

            /// <summary>
            /// Remove All Session Variables for class Shared
            /// </summary>
            public static void ClearAll()
            {
                Clear("UserName");
                Clear("MachineID");
                Clear("Theme");
                Clear("WebUserId");
                Clear("Culture");
            }
            
            /// <summary>
            /// userObj
            /// </summary>
            protected Dictionary<string, string> userObj;


            /// <summary>
            /// Gets or sets the machine ID.
            /// </summary>
            /// <value>The machine ID.</value>
            public string MachineID
            {
                get
                {
                    if (HttpContext.Current != null)
                    {
                        userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                        if (userObj == null) return "system";
                        return Convert.ToString(userObj["MachineID"]);
                    }
                    return null;
                }
                set
                {
                    if (string.IsNullOrEmpty(value)) return;
                    
                    userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                    userObj["MachineID"] = value;
                    HttpContext.Current.Session["UserObj"] = userObj;
                }
            }

            /// <summary>
            /// Gets or sets the theme.
            /// </summary>
            /// <value>The theme.</value>
            public string Theme
            {
                get
                {
                    if (HttpContext.Current != null)
                    {
                        userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                        if (userObj["Theme"] == null) return "RedPlanet";
                        return Convert.ToString(userObj["Theme"]);
                    }
                    return null;
                }
                set
                {
                    if (string.IsNullOrEmpty(value)) return;
                    
                    userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                    userObj["Theme"] = value;
                    HttpContext.Current.Session["UserObj"] = userObj;
                }
            }

            /// <summary>
            /// Gets or sets the culture.
            /// </summary>
            /// <value>The culture.</value>
            public string Culture
            {
                get
                {
                    if (HttpContext.Current != null)
                    {
                        userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                        if (userObj == null) return "en-us";
                        return Convert.ToString(userObj["Culture"]);
                    }
                    return null;
                }
                set
                {
                    if (string.IsNullOrEmpty(value)) return;
                    
                    userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                    userObj["Culture"] = value;
                    HttpContext.Current.Session["UserObj"] = userObj;
                }
            }

            /// <summary>
            /// Gets or sets the sid.
            /// </summary>
            /// <value>The sid.</value>
            public string Sid
            {
                get
                {
                    if (HttpContext.Current != null)
                    {
                        userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                        if (userObj == null) return null;
                        return Convert.ToString(userObj["Sid"]);
                    }
                    return null;
                }
                set
                {
                    if (string.IsNullOrEmpty(value)) return;
                    
                    userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                    userObj["Sid"] = value;
                    HttpContext.Current.Session["UserObj"] = userObj;
                }
            }

            /// <summary>
            /// Gets or sets the name of the user.
            /// </summary>
            /// <value>The name of the user.</value>
            public string UserName
            {
                get
                {
                    if (HttpContext.Current != null)
                    {
                        userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                        if (userObj == null) return null;
                        return Convert.ToString(userObj["UserName"]);
                    }
                    return null;
                }
                set
                {
                    if (string.IsNullOrEmpty(value)) return;
                    
                    userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                    userObj["UserName"] = value;
                    HttpContext.Current.Session["UserObj"] = userObj;
                }
            }

            /// <summary>
            /// Gets or sets the mes user id.
            /// </summary>
            /// <value>The mes user id.</value>
            public string WebUserId
            {
                get
                {
                    if (HttpContext.Current != null)
                    {
                        userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                        if (userObj == null) return "999";
                        return Convert.ToString(userObj["WebUserId"]);
                    }
                    return null;
                }
                set
                {
                    if (string.IsNullOrEmpty(value)) return;
                    
                    userObj = (Dictionary<string, string>)HttpContext.Current.Session["UserObj"];
                    userObj["WebUserId"] = value;
                    HttpContext.Current.Session["UserObj"] = userObj;
                }
            }
            
        }
    }
}